package dao.impl;

import dao.UserDao;
import entity.User;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import utils.JdbcUtils;

import java.util.List;

public class UserDaoImpl implements UserDao {
    private JdbcTemplate jdbcTemplate= JdbcUtils.getJdbcTemplate();
    public List<User> selectUser(String name) {
        String sql="select * from t_user where user_name=? ";
        List<User> list=jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(User.class),name);

        return list.isEmpty()?null:list;
    }

    @Override
    public int addUser(String name, String psw) {
        String sql="insert  into t_user(user_name,password,status) values(?,?,?) ";
        int n=jdbcTemplate.update(sql,name,psw,1);
        return n;
    }
}
